package com.smart.spring_boot_empty.service.impl;

import com.smart.spring_boot_empty.domain.entity.User;
import com.smart.spring_boot_empty.domain.dao.UserMapper;
import com.smart.spring_boot_empty.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service(value = "userService")
public class UserServiceImpl implements IUserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public void create(User user){
        userMapper.insert(user); // .update("insert into USER(NAME, AGE) values(?, ?)", user.getName(), user.getAge());
    }

    @Override
    public void deleteById(Integer id) {
        userMapper.deleteByPrimaryKey(id);
//        jdbcTemplate.update("delete from USER where NAME = ?", name);
    }

    @Override
    public List<User> getAllUsers(int pageNum, int pageSize) {
        return userMapper.selectAll(); // jdbcTemplate.queryForObject("select count(1) from USER", Integer.class);
    }

    @Override
    public void deleteAllUsers() {
//        userRepo.update("delete from USER");
        userMapper.deleteAll();
    }

    @Override
    public void updateUser(User user)
    {
        userMapper.updateByPrimaryKey(user);
    }


    @Override
    public User getUser(int id)
    {
        return userMapper.selectByPrimaryKey(id);
    }
}
